package com.wva.video.service.impl;

import com.wva.common.enums.ObjectName;
import com.wva.minio.utils.MinIOUtils;
import com.wva.video.service.VideoResourceService;
import io.minio.GetPresignedObjectUrlArgs;
import io.minio.http.Method;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Author: hong
 * @Date: 2025/2/8 23:03:47
 */
@Service
@Slf4j
public class VideoResourceServiceImpl implements VideoResourceService {
    @Autowired
    MinIOUtils minIOUtils;

    @Override
    public String getVideoObjectAccessUrlByMd5(String objectName, int timeout, TimeUnit timeUnit) throws Exception {
        return minIOUtils.getClient().getPresignedObjectUrl(
                GetPresignedObjectUrlArgs.builder()
                        .method(Method.GET)
                        .bucket(ObjectName.UPLOAD.getBucket().getBucketName())
                        .object(objectName)
                        .expiry(timeout, timeUnit)
                        .build()
        );
    }
}
